// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <melon/config.h>
#include <turbo/flags/parse.h>

TURBO_FLAG(int32_t,
           codel_interval, 100, "Codel default interval time in ms");
TURBO_FLAG(int32_t,
           codel_target_delay, 5, "Target codel queueing delay in ms");

TURBO_FLAG(bool,
    dynamic_cputhreadpoolexecutor,
    true,
    "CPUThreadPoolExecutor will dynamically create and destroy threads");

TURBO_FLAG(uint32_t,
    melon_global_io_executor_threads,
    0,
    "Number of threads global IOThreadPoolExecutor will create");

TURBO_FLAG(uint32_t,
    melon_global_cpu_executor_threads,
    0,
    "Number of threads global CPUThreadPoolExecutor will create");

TURBO_FLAG(bool,
    melon_global_cpu_executor_use_throttled_lifo_sem,
    true,
    "Use ThrottledLifoSem in global CPUThreadPoolExecutor");

TURBO_FLAG(uint32_t,
    melon_global_cpu_executor_wake_up_interval_us,
    0,
    "If --melon_global_cpu_executor_use_throttled_lifo_sem is true, use this "
    "wake-up interval (in microseconds) in ThrottledLifoSem");

TURBO_FLAG(bool,
    dynamic_iothreadpoolexecutor,
    true,
    "IOThreadPoolExecutor will dynamically create threads");
TURBO_FLAG(int64_t,
    threadtimeout_ms,
    60000,
    "Idle time before ThreadPoolExecutor threads are joined");

TURBO_FLAG(bool,
    melon_futures_use_thread_wheel_timekeeper,
    false,
    "Use ThreadWheelTimekeeper for the default Future timekeeper singleton");

TURBO_FLAG(std::string,
    melon_event_base_poller_backend,
    "epoll",
    "Available EventBasePoller backends: \"epoll\", \"io_uring\"");
TURBO_FLAG(uint64_t,
    melon_event_base_poller_spin_us,
    10,
    "Spin-wait for events up to this amount before blocking wait");
TURBO_FLAG(uint64_t,
    melon_event_base_poller_sleep_us,
    0,
    "Sleep for this amount before doing a blocking wait for events");

// Epoll backend.
TURBO_FLAG(uint64_t,
    melon_event_base_poller_epoll_max_events,
    64,
    "Maximum number of events to process in one iteration when "
    "using the epoll EventBasePoller backend");
TURBO_FLAG(bool,
    melon_event_base_poller_epoll_rearm_inline,
    true,
    "When using epoll backend, re-arm events inline in handoff() instead of "
    "returning them to the poller thread");

// io_uring backend.
TURBO_FLAG(uint64_t,
    melon_event_base_poller_io_uring_sq_entries,
    128,
    "Minimum number of entries to allocate for the submission queue when "
    "using the io_uring EventBasePoller backend");

TURBO_FLAG(bool,
    melon_hazptr_use_executor,
    true,
    "Use an executor for hazptr asynchronous reclamation");

TURBO_FLAG(bool,
    melon_memory_idler_purge_arenas,
    false,
    "if enabled, melon memory-idler purges jemalloc arenas on thread idle");

TURBO_FLAG(int32_t,
    observer_manager_pool_size,
    4,
    "How many internal threads ObserverManager should use");

namespace melon {

    void parse_args(int argc, char** argv, bool verbose) {
        TURBO_UNUSED(verbose);
        std::vector<turbo::UnrecognizedFlag> unrecognized;
        std::vector<char *>  positional_args;
        turbo::parse_turbo_flags_only(argc, argv, positional_args, unrecognized);
    }
}
